﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;

    public class Owner : BasePage
    {
        protected Button btnCopy;
        protected Button btnDelete;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected Button btnSaveAuthorizedUser;
        protected CheckBox CheckBox1;
        protected CheckBox CheckBox2;
        protected CheckBox chkboxIsCopyASN2Lot01;
        protected CheckBox chkboxIsCopyASN2Lot02;
        protected CheckBox chkboxIsCopyASN2Lot03;
        protected CheckBox chkboxIsCopyASN2Lot04;
        protected CheckBox chkboxIsCopyASN2Lot05;
        protected CheckBox chkFinanceLogisticalCtrl;
        protected CheckBox chkIsActive;
        protected CheckBox chkSameAsAddress;
        protected CheckBox chkSameWeightByStyle;
        protected CheckBox ckbCheckTheWeightDifference;
        protected CheckBox ckbIsRequiredExternalID;
        protected DropDownList ddlCalulatPutawayLocation;
        protected DropDownList ddlDefaultAllocateRuleID;
        protected DropDownList ddlDefaultCartonGroup;
        protected DropDownList ddlDefaultLotTemplateID;
        protected DropDownList ddlDefaultPreallocateRuleID;
        protected DropDownList ddlDefaultPutawayRuleID;
        protected DropDownList ddlDefaultRotationRuleID;
        protected DropDownList ddlDifferencesInApproach;
        protected DropDownList ddlFinanceLogisticalCalcBy;
        protected DropDownList ddlReceiptType;
        protected DropDownList ddlReciptValidationID;
        protected HtmlGenericControl divL7;
        protected HtmlGenericControl divR7;
        protected DropDownList DropDownList1;
        protected HtmlForm F2011;
        protected HtmlInputHidden hdnAuthorizedUser;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnImgName;
        protected HtmlInputHidden hdnImgpath;
        protected HtmlInputHidden hdnUnauthorizedUser;
        protected HtmlHead Head1;
        protected ImageButton imgAuthorizedUser;
        protected System.Web.UI.WebControls.Image imgReportTitle;
        protected ImageButton imgUnauthorizedUser;
        protected Label Label6;
        protected Label Label8;
        protected Label lblAddress;
        protected Label lblASNPrefix;
        protected Label lblASNRefer01;
        protected Label lblASNRefer02;
        protected Label lblASNRefer03;
        protected Label lblASNRefer04;
        protected Label lblASNRefer05;
        protected Label lblAuthorizedUser;
        protected Label lblBillAddress;
        protected Label lblBillCity;
        protected Label lblBillContact1;
        protected Label lblBillContact2;
        protected Label lblBillCountry;
        protected Label lblBillEmail1;
        protected Label lblBillEmail2;
        protected Label lblBillFax1;
        protected Label lblBillFax2;
        protected Label lblBillPhone1;
        protected Label lblBillPhone2;
        protected Label lblBillProvince;
        protected Label lblBillZip;
        protected Label lblCalulatPutawayLocation;
        protected Label lblCity;
        protected Label lblContact1;
        protected Label lblContact2;
        protected Label lblCountry;
        protected Label lblCreditLimit;
        protected Label lblDefaultAllocateRuleID;
        protected Label lblDefaultCartonGroup;
        protected Label lblDefaultLotTemplateID;
        protected Label lblDefaultPackID;
        protected Label lblDefaultPackingLocation;
        protected Label lblDefaultPreallocateRuleID;
        protected Label lblDefaultPutawayRuleID;
        protected Label lblDefaultQcLoc;
        protected Label lblDefaultQcLocOut;
        protected Label lblDefaultReturnsLoc;
        protected Label lblDefaultRotationRuleID;
        protected Label lblDescr;
        protected Label lblDifferencesInApproach;
        protected Label lblEmail1;
        protected Label lblEmail2;
        protected Label lblFax1;
        protected Label lblFax2;
        protected Label lblFinanceLogisticalCalcBy;
        protected Label lblLotAttr01;
        protected Label lblLotAttr02;
        protected Label lblLotAttr03;
        protected Label lblLotAttr04;
        protected Label lblLotAttr05;
        protected Label lblMsg;
        protected Label lblOwner;
        protected Label lblOwnerID;
        protected Label lblOwnerName;
        protected Label lblPercentageWeightDifference;
        protected Label lblPhone1;
        protected Label lblPhone2;
        protected Label lblPOPrefix;
        protected Label lblProvince;
        protected Label lblReciptValidationID;
        protected Label lblRemark;
        protected Label lblSOPrefix;
        protected Label lblUnauthorizedUser;
        protected Label lblUserDefine1;
        protected Label lblUserDefine10;
        protected Label lblUserDefine2;
        protected Label lblUserDefine3;
        protected Label lblUserDefine4;
        protected Label lblUserDefine5;
        protected Label lblUserDefine6;
        protected Label lblUserDefine7;
        protected Label lblUserDefine8;
        protected Label lblUserDefine9;
        protected Label lblVAT;
        protected Label lblZip;
        protected ListBox lbxAuthorizedUser;
        protected ListBox lbxUnauthorizedUser;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected Label one4;
        protected Label one5;
        protected Label one6;
        protected Label one7;
        protected ScriptManager ScriptManager1;
        public static int TabNum = 7;
        protected TextBox txtAddress;
        protected TextBox txtASNPrefix;
        protected TextBox txtASNRefer01;
        protected TextBox txtASNRefer02;
        protected TextBox txtASNRefer03;
        protected TextBox txtASNRefer04;
        protected TextBox txtASNRefer05;
        protected TextBox txtBillAddress;
        protected TextBox txtBillCity;
        protected TextBox txtBillConatact2;
        protected TextBox txtBillContact1;
        protected TextBox txtBillCountry;
        protected TextBox txtBillEmail1;
        protected TextBox txtBillEmail2;
        protected TextBox txtBillFax1;
        protected TextBox txtBillFax2;
        protected TextBox txtBillPhone1;
        protected TextBox txtBillPhone2;
        protected TextBox txtBillProvince;
        protected TextBox txtBillZIP;
        protected TextBox txtCity;
        protected TextBox txtConatact2;
        protected TextBox txtContact1;
        protected TextBox txtCountry;
        protected TextBox txtCreditLimit;
        protected TextBox txtDefaultPackID;
        protected TextBox txtDefaultPackingLocation;
        protected TextBox txtDefaultQcLoc;
        protected TextBox txtDefaultQcLocOut;
        protected TextBox txtDefaultReturnsLoc;
        protected TextBox txtEmail1;
        protected TextBox txtEmail2;
        protected TextBox txtFax1;
        protected TextBox txtFax2;
        protected TextBox txtLotAttr01;
        protected TextBox txtLotAttr02;
        protected TextBox txtLotAttr03;
        protected TextBox txtLotAttr04;
        protected TextBox txtLotAttr05;
        protected TextBox txtOwnerDescr;
        protected TextBox txtOwnerID;
        protected TextBox txtOwnerName;
        protected TextBox txtPercentageWeightDifference;
        protected TextBox txtPhone1;
        protected TextBox txtPhone2;
        protected TextBox txtPOPrefix;
        protected TextBox txtProvince;
        protected TextBox txtRemark;
        protected TextBox txtSOPrefix;
        protected TextBox txtUserDefine1;
        protected TextBox txtUserDefine10;
        protected TextBox txtUserDefine2;
        protected TextBox txtUserDefine3;
        protected TextBox txtUserDefine4;
        protected TextBox txtUserDefine5;
        protected TextBox txtUserDefine6;
        protected TextBox txtUserDefine7;
        protected TextBox txtUserDefine8;
        protected TextBox txtUserDefine9;
        protected TextBox txtVAT;
        protected TextBox txtZIP;
        protected UpdatePanel up1;

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtOwnerID.Text = "";
            this.txtOwnerID.Enabled = true;
            base.DataEntityViewState = null;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
            {
                try
                {
                    List<string> ownerID = new List<string> {
                        this.txtOwnerID.Text.Trim()
                    };
                    this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Delete(ownerID, "TRADE_PARTNER") + base.GetGlobalMsgResource("C006");
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnCopy.Enabled = false;
                    base.DataEntityViewState = null;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C007") + ex.Message;
                }
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("OwnerQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("OwnerList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2110_001");
            }
            else if (string.IsNullOrEmpty(this.txtOwnerName.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2110_002");
            }
            else
            {
                if (base.DataEntityViewState != null)
                {
                    this.UpdateOwnerInfo();
                }
                else
                {
                    this.InsertOwnerInfo();
                }
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',1," + TabNum + ") </script>", false);
            }
        }

        protected void btnSaveAuthorizedUser_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2110_001");
            }
            else if (this.txtOwnerID.Enabled)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2110_028");
            }
            else
            {
                string authorizationUser = string.Empty;
                DataTable dtUser = base.PageQueryEntitySession as DataTable;
                if ((dtUser != null) && (dtUser.Rows.Count > 0))
                {
                    for (int i = 0; i < dtUser.Rows.Count; i++)
                    {
                        if (dtUser.Rows[i]["PREMISSION_USER"].ToString() == "Y")
                        {
                            authorizationUser = authorizationUser + dtUser.Rows[i]["USER_ID"].ToString() + ";";
                        }
                    }
                }
                if (authorizationUser.Length > 1)
                {
                    try
                    {
                        authorizationUser = authorizationUser.Substring(0, authorizationUser.Length - 1);
                        if (CommoneMethodServiceClientProxy.GetInstance().UpdateAuthorizationUserByType(authorizationUser, "OWNER", this.txtOwnerID.Text.Trim()) > 0)
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2110_025");
                        }
                        else
                        {
                            this.lblMsg.Text = base.GetGlobalMsgResource("F2110_026");
                        }
                    }
                    catch (Exception ex)
                    {
                        this.lblMsg.Text = ex.Message;
                        return;
                    }
                }
                else
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F2110_027");
                }
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7," + TabNum + ");$.unblockUI(); </script>", false);
            }
        }

        protected void chkSameAsAddress_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chkSameAsAddress.Checked)
            {
                this.txtBillAddress.Text = this.txtAddress.Text;
                this.txtBillCity.Text = this.txtCity.Text;
                this.txtBillConatact2.Text = this.txtConatact2.Text;
                this.txtBillContact1.Text = this.txtContact1.Text;
                this.txtBillCountry.Text = this.txtCountry.Text;
                this.txtBillEmail1.Text = this.txtEmail1.Text;
                this.txtBillEmail2.Text = this.txtEmail2.Text;
                this.txtBillFax1.Text = this.txtFax1.Text;
                this.txtBillFax2.Text = this.txtFax2.Text;
                this.txtBillPhone1.Text = this.txtPhone1.Text;
                this.txtBillPhone2.Text = this.txtPhone2.Text;
                this.txtBillProvince.Text = this.txtProvince.Text;
                this.txtBillZIP.Text = this.txtZIP.Text;
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3," + TabNum + ");</script>", false);
            }
        }

        private TradePartnerInfo GetOwnerFromForm(TradePartnerInfo ownerInfo)
        {
            ownerInfo.OwnerID = this.txtOwnerID.Text.Trim();
            ownerInfo.Company = this.txtOwnerName.Text.Trim();
            ownerInfo.Description = this.txtOwnerDescr.Text.Trim();
            ownerInfo.PoAlphaPrefix = this.txtPOPrefix.Text.Trim();
            ownerInfo.SoAlphaPrefix = this.txtSOPrefix.Text.Trim();
            ownerInfo.AsnAlphaPrefix = this.txtASNPrefix.Text.Trim();
            ownerInfo.Vat = this.txtVAT.Text.Trim();
            ownerInfo.CreditLimit = this.txtCreditLimit.Text.Trim();
            ownerInfo.Type = "1";
            ownerInfo.IsActive = this.chkIsActive.Checked ? "Y" : "N";
            ownerInfo.CreatePaTaskOnRfReceipt = "";
            ownerInfo.OrderBreakDefault = "";
            ownerInfo.LpnStartNumber = "";
            ownerInfo.NextLpnNumber = "";
            ownerInfo.LpnRollbackNumber = "";
            ownerInfo.CaseLabelType = "";
            ownerInfo.ApplicationID = "";
            ownerInfo.UccVendorNumber = "";
            ownerInfo.CcDiscrepancyRule = "";
            ownerInfo.CcAdjByRf = "";
            ownerInfo.CcSkuLoc = "";
            ownerInfo.PiSkuLoc = "";
            ownerInfo.AllowAutoCloseForAsn = "";
            ownerInfo.AllowAutoCloseForPo = "";
            ownerInfo.AllowCommingledLpn = "";
            ownerInfo.AllowOverShipment = "";
            ownerInfo.AllowSingleScanreceiving = "";
            ownerInfo.AllowSystemGeneratedLpn = "";
            ownerInfo.BarcodeConfigID = "";
            ownerInfo.SkuSetupRequired = "";
            ownerInfo.Sscc1stDigit = 0;
            ownerInfo.DefaultCartonGroup = this.ddlDefaultCartonGroup.SelectedValue;
            ownerInfo.DefaultPutawayRuleID = this.ddlDefaultPutawayRuleID.SelectedValue;
            ownerInfo.ReceiptValidationID = this.ddlReciptValidationID.SelectedValue;
            ownerInfo.DefaultQcLoc = this.txtDefaultQcLoc.Text.Trim();
            ownerInfo.DefaultPackID = this.txtDefaultPackID.Text.Trim();
            ownerInfo.DefaultPreallocateRuleID = this.ddlDefaultPreallocateRuleID.SelectedValue;
            ownerInfo.DefaultQcLocOut = this.txtDefaultQcLocOut.Text.Trim();
            ownerInfo.DefaultLotTemplateID = this.ddlDefaultLotTemplateID.SelectedValue;
            ownerInfo.DefaultAllocateRuleID = this.ddlDefaultAllocateRuleID.SelectedValue;
            ownerInfo.DefaultReturnsLoc = this.txtDefaultReturnsLoc.Text.Trim();
            ownerInfo.DefaultRotationRuleID = this.ddlDefaultRotationRuleID.SelectedValue;
            ownerInfo.DefaultPackingLocation = this.txtDefaultPackingLocation.Text.Trim();
            ownerInfo.CalculatePutawayLocation = this.ddlCalulatPutawayLocation.SelectedValue;
            ownerInfo.Finance_Logistical_Calc_By = this.ddlFinanceLogisticalCalcBy.SelectedValue;
            ownerInfo.IsAsnreferToLot01 = this.chkboxIsCopyASN2Lot01.Checked ? "Y" : "N";
            ownerInfo.IsAsnreferToLot02 = this.chkboxIsCopyASN2Lot02.Checked ? "Y" : "N";
            ownerInfo.IsAsnreferToLot03 = this.chkboxIsCopyASN2Lot03.Checked ? "Y" : "N";
            ownerInfo.IsAsnreferToLot04 = this.chkboxIsCopyASN2Lot04.Checked ? "Y" : "N";
            ownerInfo.IsAsnreferToLot05 = this.chkboxIsCopyASN2Lot05.Checked ? "Y" : "N";
            ownerInfo.AsnRefer01 = this.txtASNRefer01.Text.Trim();
            ownerInfo.AsnRefer02 = this.txtASNRefer02.Text.Trim();
            ownerInfo.AsnRefer03 = this.txtASNRefer03.Text.Trim();
            ownerInfo.AsnRefer04 = this.txtASNRefer04.Text.Trim();
            ownerInfo.AsnRefer05 = this.txtASNRefer05.Text.Trim();
            ownerInfo.AsnToLotAttr01 = this.txtLotAttr01.Text.Trim();
            ownerInfo.AsnToLotAttr02 = this.txtLotAttr02.Text.Trim();
            ownerInfo.AsnToLotAttr03 = this.txtLotAttr03.Text.Trim();
            ownerInfo.AsnToLotAttr04 = this.txtLotAttr04.Text.Trim();
            ownerInfo.AsnToLotAttr05 = this.txtLotAttr05.Text.Trim();
            ownerInfo.City = this.txtCity.Text.Trim();
            ownerInfo.State = this.txtProvince.Text.Trim();
            ownerInfo.Contact1 = this.txtContact1.Text.Trim();
            ownerInfo.Contact2 = this.txtConatact2.Text.Trim();
            ownerInfo.Country = this.txtCountry.Text.Trim();
            ownerInfo.Zip = this.txtZIP.Text.Trim();
            ownerInfo.Phone1 = this.txtPhone1.Text.Trim();
            ownerInfo.Phone2 = this.txtPhone2.Text.Trim();
            ownerInfo.Address = this.txtAddress.Text.Trim();
            ownerInfo.Fax1 = this.txtFax1.Text.Trim();
            ownerInfo.Fax2 = this.txtFax2.Text.Trim();
            ownerInfo.Email1 = this.txtEmail1.Text.Trim();
            ownerInfo.Email2 = this.txtEmail2.Text.Trim();
            ownerInfo.BCity = this.txtBillCity.Text.Trim();
            ownerInfo.BState = this.txtProvince.Text.Trim();
            ownerInfo.BContact1 = this.txtBillContact1.Text.Trim();
            ownerInfo.BContact2 = this.txtBillConatact2.Text.Trim();
            ownerInfo.BCountry = this.txtBillCountry.Text.Trim();
            ownerInfo.BZip = this.txtBillZIP.Text.Trim();
            ownerInfo.BPhone1 = this.txtBillPhone1.Text.Trim();
            ownerInfo.BPhone2 = this.txtBillPhone2.Text.Trim();
            ownerInfo.BAddress = this.txtBillAddress.Text.Trim();
            ownerInfo.BFax1 = this.txtBillFax1.Text.Trim();
            ownerInfo.BFax2 = this.txtBillFax2.Text.Trim();
            ownerInfo.BEmail1 = this.txtBillEmail1.Text.Trim();
            ownerInfo.BEmail2 = this.txtBillEmail2.Text.Trim();
            ownerInfo.Udf1 = this.txtUserDefine1.Text.Trim();
            ownerInfo.Udf2 = this.txtUserDefine2.Text.Trim();
            ownerInfo.Udf3 = this.txtUserDefine3.Text.Trim();
            ownerInfo.Udf4 = this.txtUserDefine4.Text.Trim();
            ownerInfo.Udf5 = this.txtUserDefine5.Text.Trim();
            ownerInfo.Udf6 = this.txtUserDefine6.Text.Trim();
            ownerInfo.Udf7 = this.txtUserDefine7.Text.Trim();
            ownerInfo.Udf8 = this.txtUserDefine8.Text.Trim();
            ownerInfo.Udf9 = this.hdnImgName.Value;
            ownerInfo.Udf10 = this.txtUserDefine10.Text.Trim();
            ownerInfo.IsRequiredExternalID = this.ckbIsRequiredExternalID.Checked ? "Y" : "N";
            ownerInfo.Remark = this.txtRemark.Text.Trim();
            ownerInfo.SameWeightByStyle = this.chkSameWeightByStyle.Checked ? "Y" : "N";
            ownerInfo.Finance_Logistical_Ctrl = this.chkFinanceLogisticalCtrl.Checked ? "Y" : "N";
            ownerInfo.CheckTheWeightDifference = this.ckbCheckTheWeightDifference.Checked ? "Y" : "N";
            ownerInfo.PercentageWeightDifference = decimal.Parse(string.IsNullOrEmpty(this.txtPercentageWeightDifference.Text.Trim()) ? "0" : this.txtPercentageWeightDifference.Text.Trim());
            ownerInfo.DifferencesInApproach = this.ddlDifferencesInApproach.SelectedValue;
            return ownerInfo;
        }

        protected void imgAuthorizedUser_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnAuthorizedUser.Value))
            {
                DataTable dtUser = base.PageQueryEntitySession as DataTable;
                string[] strAuthorizedUser = this.hdnAuthorizedUser.Value.Split(new char[] { ';' });
                for (int i = 0; i < dtUser.Rows.Count; i++)
                {
                    if (dtUser.Rows[i]["PREMISSION_USER"].ToString() == "Y")
                    {
                        for (int j = 0; strAuthorizedUser.Length > j; j++)
                        {
                            if (dtUser.Rows[i]["USER_ID"].ToString() == strAuthorizedUser[j])
                            {
                                dtUser.Rows[i]["PREMISSION_USER"] = "N";
                                break;
                            }
                        }
                    }
                }
                base.PageQueryEntitySession = dtUser;
                this.hdnAuthorizedUser.Value = string.Empty;
                this.SetControlslbxUserData(dtUser);
            }
            if (this.lbxUnauthorizedUser.Items.Count > 0)
            {
                this.lbxUnauthorizedUser.Items[0].Selected = true;
                this.lbxUnauthorizedUser_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7," + TabNum + ") </script>", false);
        }

        protected void imgUnauthorizedUser_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(this.hdnUnauthorizedUser.Value))
            {
                DataTable dtUser = base.PageQueryEntitySession as DataTable;
                string[] strUnauthorizedUser = this.hdnUnauthorizedUser.Value.Split(new char[] { ';' });
                for (int i = 0; i < dtUser.Rows.Count; i++)
                {
                    if (dtUser.Rows[i]["PREMISSION_USER"].ToString() == "N")
                    {
                        for (int j = 0; strUnauthorizedUser.Length > j; j++)
                        {
                            if (dtUser.Rows[i]["USER_ID"].ToString() == strUnauthorizedUser[j])
                            {
                                dtUser.Rows[i]["PREMISSION_USER"] = "Y";
                                break;
                            }
                        }
                    }
                }
                base.PageQueryEntitySession = dtUser;
                this.hdnUnauthorizedUser.Value = string.Empty;
                this.SetControlslbxUserData(dtUser);
            }
            if (this.lbxAuthorizedUser.Items.Count > 0)
            {
                this.lbxAuthorizedUser.Items[0].Selected = true;
                this.lbxAuthorizedUser_SelectedIndexChanged(sender, e);
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7," + TabNum + ") </script>", false);
        }

        private void InitDropDownList()
        {
            base.BindData2DDLBySysCode(this.ddlCalulatPutawayLocation, "TMCalculateLoc");
            base.BindData2DDLBySysCode(this.ddlFinanceLogisticalCalcBy, "FinanceLogistical");
            base.BindData2DDLByRules(this.ddlDefaultPutawayRuleID, "PutawayRule");
            base.BindData2DDLByRules(this.ddlDefaultPreallocateRuleID, "PreallocateRule");
            base.BindData2DDLByRules(this.ddlDefaultAllocateRuleID, "AllocateRule");
            base.BindData2DDLByRules(this.ddlDefaultRotationRuleID, "RotationRule");
            base.BindData2DDLBySysCode(this.ddlDifferencesInApproach, "ValidationOption");
            base.BindData2DDLByCartonGroup(this.ddlDefaultCartonGroup);
            base.BindData2DDLByLotTemplate(this.ddlDefaultLotTemplateID);
            base.BindData2DDLByReceiptValidation(this.ddlReciptValidationID);
        }

        private void InsertOwnerInfo()
        {
            try
            {
                TradePartnerInfo ownerInfo = new TradePartnerInfo();
                ownerInfo = this.GetOwnerFromForm(ownerInfo);
                ownerInfo.CreatedBy = base.UserInfo.UserID;
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Insert(ownerInfo, "TRADE_PARTNER") + base.GetGlobalMsgResource("C004");
                base.DataEntityViewState = ownerInfo;
                this.txtOwnerID.Enabled = false;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C005") + ex.Message;
            }
        }

        protected void lbxAuthorizedUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnAuthorizedUser.Value = "";
            if (this.lbxAuthorizedUser.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxAuthorizedUser.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnAuthorizedUser.Value = this.hdnAuthorizedUser.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnAuthorizedUser.Value))
                {
                    this.hdnAuthorizedUser.Value = this.hdnAuthorizedUser.Value.Substring(0, this.hdnAuthorizedUser.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7," + TabNum + ") </script>", false);
        }

        protected void lbxUnauthorizedUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.hdnUnauthorizedUser.Value = "";
            if (this.lbxUnauthorizedUser.Items.Count > 0)
            {
                foreach (ListItem info in this.lbxUnauthorizedUser.Items)
                {
                    if (info.Selected)
                    {
                        this.hdnUnauthorizedUser.Value = this.hdnUnauthorizedUser.Value + info.Value + ";";
                    }
                }
                if (!string.IsNullOrEmpty(this.hdnUnauthorizedUser.Value))
                {
                    this.hdnUnauthorizedUser.Value = this.hdnUnauthorizedUser.Value.Substring(0, this.hdnUnauthorizedUser.Value.Length - 1);
                }
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", " <script type=\"text/javascript\" >setTab('one',7," + TabNum + ") </script>", false);
        }

        private void LoadData()
        {
            this.InitDropDownList();
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.SetOwnerInfo2Form();
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            this.SetAuthorizationUser();
        }

        public void MakeThumbnail(Stream stream, string thumbnailPath, int width, int height, string mode)
        {
            System.Drawing.Image originalImage = System.Drawing.Image.FromStream(stream);
            int towidth = width;
            int toheight = height;
            int x = 0;
            int y = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;
            string CS40000 = mode;
            if ((CS40000 != null) && (CS40000 != "HW"))
            {
                if (!(CS40000 == "W"))
                {
                    if (CS40000 == "H")
                    {
                        towidth = (originalImage.Width * height) / originalImage.Height;
                    }
                    else if (CS40000 == "Cut")
                    {
                        if ((((double) originalImage.Width) / ((double) originalImage.Height)) > (((double) towidth) / ((double) toheight)))
                        {
                            oh = originalImage.Height;
                            ow = (originalImage.Height * towidth) / toheight;
                            y = 0;
                            x = (originalImage.Width - ow) / 2;
                        }
                        else
                        {
                            ow = originalImage.Width;
                            oh = (originalImage.Width * height) / towidth;
                            x = 0;
                            y = (originalImage.Height - oh) / 2;
                        }
                    }
                }
                else
                {
                    toheight = (originalImage.Height * width) / originalImage.Width;
                }
            }
            System.Drawing.Image bitmap = new Bitmap(towidth, toheight);
            Graphics g = Graphics.FromImage(bitmap);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.Clear(Color.Transparent);
            g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight), new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel);
            try
            {
                MemoryStream temp = new MemoryStream();
                bitmap.Save(temp, ImageFormat.Jpeg);
                using (Stream localFile = new FileStream(thumbnailPath, FileMode.OpenOrCreate))
                {
                    localFile.Write(temp.ToArray(), 0, (int) temp.Length);
                }
            }
            catch (Exception e)
            {
                this.lblMsg.Text = e.Message;
            }
            finally
            {
                originalImage.Dispose();
                bitmap.Dispose();
                g.Dispose();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetAuthorizationUser()
        {
            if ((base.UserInfo.IsGlobal == "Y") && (base.UserInfo.IsPremissionsFunctionID == "Y"))
            {
                DataSet userDS = CommoneMethodServiceClientProxy.GetInstance().GetAuthorizationUserByType("OWNER", this.txtOwnerID.Text.Trim());
                if ((userDS != null) && (userDS.Tables[0].Rows.Count > 0))
                {
                    if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                    {
                        for (int i = 0; i < userDS.Tables[0].Rows.Count; i++)
                        {
                            userDS.Tables[0].Rows[i]["PREMISSION_USER"] = "Y";
                        }
                    }
                    this.SetControlslbxUserData(userDS.Tables[0]);
                    base.PageQueryEntitySession = userDS.Tables[0];
                }
                TabNum = 7;
            }
            else
            {
                this.one7.Visible = false;
                this.divL7.Visible = false;
                this.divR7.Visible = false;
                TabNum = 6;
            }
        }

        private void SetControlslbxUserData(DataTable dtUser)
        {
            DataRow[] drAuthorizedUser = dtUser.Select("PREMISSION_USER = 'Y'");
            DataTable dtAuthorizedUser = new DataTable();
            dtAuthorizedUser = dtUser.Clone();
            foreach (DataRow dr in drAuthorizedUser)
            {
                dtAuthorizedUser.ImportRow(dr);
            }
            this.lbxAuthorizedUser.DataSource = dtAuthorizedUser;
            this.lbxAuthorizedUser.DataTextField = "USER_NAME";
            this.lbxAuthorizedUser.DataValueField = "USER_ID";
            this.lbxAuthorizedUser.DataBind();
            DataRow[] drUnauthorizedUser = dtUser.Select("PREMISSION_USER <> 'Y'");
            DataTable dtUnauthorizedUser = new DataTable();
            dtUnauthorizedUser = dtUser.Clone();
            foreach (DataRow dr in drUnauthorizedUser)
            {
                dtUnauthorizedUser.ImportRow(dr);
            }
            this.lbxUnauthorizedUser.DataSource = dtUnauthorizedUser;
            this.lbxUnauthorizedUser.DataTextField = "USER_NAME";
            this.lbxUnauthorizedUser.DataValueField = "USER_ID";
            this.lbxUnauthorizedUser.DataBind();
        }

        private void SetOwnerInfo2Form()
        {
            try
            {
                string ownerID = base.Request.QueryString["ID"].ToString();
                TradePartnerInfo owner = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(ownerID, "TRADE_PARTNER") as TradePartnerInfo;
                if (owner != null)
                {
                    base.DataEntityViewState = owner;
                    this.txtOwnerID.Text = owner.OwnerID;
                    this.txtOwnerName.Text = owner.Company;
                    this.txtOwnerDescr.Text = owner.Description;
                    this.txtPOPrefix.Text = owner.PoAlphaPrefix;
                    this.txtSOPrefix.Text = owner.SoAlphaPrefix;
                    this.txtASNPrefix.Text = owner.AsnAlphaPrefix;
                    this.txtVAT.Text = owner.Vat;
                    this.txtCreditLimit.Text = owner.CreditLimit;
                    if (!string.IsNullOrEmpty(owner.IsRequiredExternalID) && (owner.IsRequiredExternalID.ToUpper() == "Y"))
                    {
                        this.ckbIsRequiredExternalID.Checked = true;
                    }
                    this.ckbCheckTheWeightDifference.Checked = owner.CheckTheWeightDifference == "Y";
                    this.txtPercentageWeightDifference.Text = base.GetPreferenceDigit(owner.PercentageWeightDifference);
                    if (!string.IsNullOrEmpty(owner.DifferencesInApproach))
                    {
                        this.ddlDifferencesInApproach.SelectedValue = owner.DifferencesInApproach;
                    }
                    this.chkIsActive.Checked = owner.IsActive == "Y";
                    this.chkSameWeightByStyle.Checked = owner.SameWeightByStyle == "Y";
                    this.chkFinanceLogisticalCtrl.Checked = owner.Finance_Logistical_Ctrl == "Y";
                    this.ddlDefaultCartonGroup.SelectedValue = owner.DefaultCartonGroup;
                    this.ddlDefaultPutawayRuleID.SelectedValue = owner.DefaultPutawayRuleID;
                    this.ddlReciptValidationID.SelectedValue = owner.ReceiptValidationID;
                    this.txtDefaultQcLoc.Text = owner.DefaultQcLoc;
                    this.txtDefaultPackID.Text = owner.DefaultPackID;
                    this.ddlDefaultPreallocateRuleID.SelectedValue = owner.DefaultPreallocateRuleID;
                    this.txtDefaultQcLocOut.Text = owner.DefaultQcLocOut;
                    this.ddlDefaultLotTemplateID.SelectedValue = owner.DefaultLotTemplateID;
                    this.ddlDefaultAllocateRuleID.SelectedValue = owner.DefaultAllocateRuleID;
                    this.txtDefaultReturnsLoc.Text = owner.DefaultReturnsLoc;
                    this.ddlDefaultRotationRuleID.SelectedValue = owner.DefaultRotationRuleID;
                    this.txtDefaultPackingLocation.Text = owner.DefaultPackingLocation;
                    this.ddlCalulatPutawayLocation.SelectedValue = owner.CalculatePutawayLocation;
                    this.ddlFinanceLogisticalCalcBy.SelectedValue = owner.Finance_Logistical_Calc_By;
                    this.chkboxIsCopyASN2Lot01.Checked = !string.IsNullOrEmpty(owner.IsAsnreferToLot01) && (owner.IsAsnreferToLot01 == "Y");
                    this.chkboxIsCopyASN2Lot02.Checked = !string.IsNullOrEmpty(owner.IsAsnreferToLot02) && (owner.IsAsnreferToLot02 == "Y");
                    this.chkboxIsCopyASN2Lot03.Checked = !string.IsNullOrEmpty(owner.IsAsnreferToLot03) && (owner.IsAsnreferToLot03 == "Y");
                    this.chkboxIsCopyASN2Lot04.Checked = !string.IsNullOrEmpty(owner.IsAsnreferToLot04) && (owner.IsAsnreferToLot04 == "Y");
                    this.chkboxIsCopyASN2Lot05.Checked = !string.IsNullOrEmpty(owner.IsAsnreferToLot05) && (owner.IsAsnreferToLot05 == "Y");
                    this.txtASNRefer01.Text = owner.AsnRefer01;
                    this.txtASNRefer02.Text = owner.AsnRefer02;
                    this.txtASNRefer03.Text = owner.AsnRefer03;
                    this.txtASNRefer04.Text = owner.AsnRefer04;
                    this.txtASNRefer05.Text = owner.AsnRefer05;
                    this.txtLotAttr01.Text = owner.AsnToLotAttr01;
                    this.txtLotAttr02.Text = owner.AsnToLotAttr02;
                    this.txtLotAttr03.Text = owner.AsnToLotAttr03;
                    this.txtLotAttr04.Text = owner.AsnToLotAttr04;
                    this.txtLotAttr05.Text = owner.AsnToLotAttr05;
                    this.txtCity.Text = owner.City;
                    this.txtProvince.Text = owner.State;
                    this.txtContact1.Text = owner.Contact1;
                    this.txtConatact2.Text = owner.Contact2;
                    this.txtCountry.Text = owner.Country;
                    this.txtZIP.Text = owner.Zip;
                    this.txtPhone1.Text = owner.Phone1;
                    this.txtPhone2.Text = owner.Phone2;
                    this.txtAddress.Text = owner.Address;
                    this.txtFax1.Text = owner.Fax1;
                    this.txtFax2.Text = owner.Fax2;
                    this.txtEmail1.Text = owner.Email1;
                    this.txtEmail2.Text = owner.Email2;
                    this.txtBillCity.Text = owner.BCity;
                    this.txtBillProvince.Text = owner.State;
                    this.txtBillContact1.Text = owner.BContact1;
                    this.txtBillConatact2.Text = owner.BContact2;
                    this.txtBillCountry.Text = owner.BCountry;
                    this.txtBillZIP.Text = owner.BZip;
                    this.txtBillPhone1.Text = owner.BPhone1;
                    this.txtBillPhone2.Text = owner.BPhone2;
                    this.txtBillAddress.Text = owner.BAddress;
                    this.txtBillFax1.Text = owner.BFax1;
                    this.txtBillFax2.Text = owner.BFax2;
                    this.txtBillEmail1.Text = owner.BEmail1;
                    this.txtBillEmail2.Text = owner.BEmail2;
                    this.txtUserDefine1.Text = owner.Udf1;
                    this.txtUserDefine2.Text = owner.Udf2;
                    this.txtUserDefine3.Text = owner.Udf3;
                    this.txtUserDefine4.Text = owner.Udf4;
                    this.txtUserDefine5.Text = owner.Udf5;
                    this.txtUserDefine6.Text = owner.Udf6;
                    this.txtUserDefine7.Text = owner.Udf7;
                    this.txtUserDefine8.Text = owner.Udf8;
                    this.txtUserDefine9.Text = owner.Udf9;
                    this.txtUserDefine10.Text = owner.Udf10;
                    this.txtRemark.Text = owner.Remark;
                    this.txtOwnerID.Enabled = false;
                    if (File.Exists(HttpContext.Current.Request.PhysicalApplicationPath + "Upload/OwnerLogo/" + owner.Udf9))
                    {
                        this.imgReportTitle.ImageUrl = "../Upload/OwnerLogo/" + owner.Udf9;
                    }
                    else
                    {
                        this.imgReportTitle.ImageUrl = "../Images/null.gif";
                    }
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void UpdateOwnerInfo()
        {
            try
            {
                TradePartnerInfo ownerInfo = base.DataEntityViewState as TradePartnerInfo;
                ownerInfo = this.GetOwnerFromForm(ownerInfo);
                ownerInfo.UpdatedBy = base.UserInfo.UserID;
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Update(ownerInfo, "TRADE_PARTNER") + base.GetGlobalMsgResource("C002");
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C003") + ex.Message;
            }
        }

        protected void UpLoadFiles(object sender, EventArgs e)
        {
        }
    }
}

